#include<iostream>
using namespace std;
struct ListNode {
	int val;
	ListNode* next;
public:
	ListNode(int num):val(num),next(nullptr){}
};
ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
	ListNode* prehead = new ListNode(-1);
	ListNode* prev = prehead;
	while (l1 != nullptr && l2 != nullptr) {
		if (l1->val < l2->val) {
			prev->next = l1;
			l1 = l1->next;
		}
		else {
			prev->next = l2;
			l2 = l2->next;
		}
		prev = prev->next;
	}

	prev->next = l1 == nullptr ? l2 : l1;
	return prehead->next;  // 返回真正的合并结果，不包含头节点
}
int main() {
	int n, m;
	cin >> n >> m;
	
	// 创建头节点
	ListNode* l1_head = new ListNode(-1);
	ListNode* l2_head = new ListNode(-1);
	ListNode* l1_tail = l1_head;
	ListNode* l2_tail = l2_head;
	
	// 构建第一个链表
	for (int i = 0; i < n; i++) {
		int num;
		cin >> num;
		ListNode* newNode = new ListNode(num);
		l1_tail->next = newNode;
		l1_tail = l1_tail->next;
	}
	
	// 构建第二个链表
	for (int i = 0; i < m; i++) {
		int num;
		cin >> num;
		ListNode* newNode = new ListNode(num);
		l2_tail->next = newNode;
		l2_tail = l2_tail->next;
	}
	
	// 合并链表
	//把-1那一节去掉
	ListNode* merged = mergeTwoLists(l1_head->next, l2_head->next);
		
	// 输出合并后的链表
	ListNode* current = merged;
	while (current != nullptr) {
		
		cout << current->val;
		if(current->next!=nullptr)cout << " ";
		current = current->next;
	}
	cout << endl;
	while (current != nullptr) {
		ListNode* nxt = current->next;
		delete current;
		current = nxt;
	}
	
	return 0;
}